import {FOCUS,BLUR,CHANGE_LIST,MOUSE_ENTER,MOUSE_LEAVE,CHANGE_PAGE} from  './actionTypes';
import axios from 'axios';
import {fromJS} from 'immutable';

const changeList=(data)=>{
    return {
        type:CHANGE_LIST,
        data:fromJS(data),
        totalPage:Math.ceil(data.length/10)
    }
}

export const getFocus=()=>{
    return {
        type:FOCUS
    }
}

export const getBlur=()=>{
    return {
        type:BLUR
    }
}

export const getEnter=()=>{
    return {
        type:MOUSE_ENTER
    }
}

export const getLeave=()=>{
    return {
        type:MOUSE_LEAVE
    }
}

export const getPage=(page)=>{
    return {
        type:CHANGE_PAGE,
        page
    }
}

export const getList=()=>{
    return (dispatch)=>{
        axios.get('https://www.fastmock.site/mock/eaa7a18e424aefd6b9ee29850969298e/api/headerList').then((res)=>{
            if(res.data.success) {
                const data=res.data.data;
                dispatch(changeList(data));
            }
        }).catch(()=>{
            console.log('error')
        })
    }
}
